<template>
  <div>
    <el-card class="box-card">
      <p class="title">美业管理系统</p>
      <el-form :model="loginForm" :rules="loginFormRules" ref="loginForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名:" prop="username">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码:" prop="password">
          <el-input v-model="loginForm.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-radio v-model="type" label="1">商户</el-radio>
          <el-radio v-model="type" label="0">平台</el-radio>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="primary" @click="register" id="register">注册</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      type: '1',
      loginForm: {
        username: '15552145263',
        password: '123456',
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' }
        ],
      },
      routerRender1: [
        {
          path: '/home',
          name: 'home',
          component: 'Home.vue',
          redirect: '/home/merchants/welcome',
          children: [
            {
              path: 'merchants/welcome',
              name: 'welcome',
              component: 'merchants/Welcome.vue',
              meta: {
                title: '主页',
                isShow: 1,
                icon: 'icon-shouye',
              },
            },
            {
              path: 'merchants/enter',
              name: 'enter',
              component: 'merchants/Enter/Enter.vue',
              meta: {
                title: '立即入驻',
                isShow: 1,
                icon: 'icon-ruzhu',
              },
            },
            {
              path: 'merchants/enterprise',
              name: 'enterprise',
              component: 'merchants/Enter/enterprise/Enterprise.vue',
              meta: {
                title: '企业信息',
                isShow: 0,
              },
            },
            {
              path: 'merchants/collection',
              name: 'collection',
              component: 'merchants/Enter/enterprise/Collection.vue',
              meta: {
                title: '收款信息',
                isShow: 0,
              },
            },
            {
              path: 'merchants/audit',
              name: 'audit',
              component: 'merchants/Enter/enterprise/Audit.vue',
              meta: {
                title: '审核信息',
                isShow: 0,
              },
            },
            {
              path: 'merchants/order',
              name: 'order',
              component: 'merchants/Order/Order.vue',
              meta: {
                title: '订单管理',
                isShow: 1,
                icon: 'icon-dingdanguanli35',
              },
            },
            {
              path: 'merchants/service',
              name: 'service',
              component: 'merchants/Service/Service.vue',
              meta: {
                title: '服务管理',
                isShow: 1,
                icon: 'icon-fuwuguanli',
              },
            },

            // 以下是服务管理其他页面的路由跳转配置
            {
              path: 'merchants/serviceDetail',
              name: 'serviceDetail',
              component: 'merchants/Service/ServiceDetail.vue',
              meta: {
                title: '服务详情' /* 服务管理中的服务详情 */,
                isShow: 0,
              },
            },
            {
              path: 'merchants/serviceAdd',
              name: 'serviceAdd',
              component: 'merchants/Service/ServiceAdd.vue',
              meta: {
                title: '新增服务' /* 服务管理中的新增服务 */,
                isShow: 0,
              },
            },
            {
              path: 'merchants/serviceEdit',
              name: 'serviceEdit',
              component: 'merchants/Service/ServiceEdit.vue',
              meta: {
                title: '编辑服务' /* 服务管理中的编辑服务 */,
                isShow: 0,
              },
            },

            {
              path: 'merchants/financial',
              name: 'financial',
              component: 'merchants/Financial/Financial.vue',
              meta: {
                title: '财务管理',
                isShow: 1,
                icon: 'icon-caiwuguanli',
              },
            },
            {
              path: 'merchants/storeSet',
              name: 'storeSet',
              component: 'merchants/StoreSet/StoreSet.vue',
              meta: {
                title: '门店设置',
                isShow: 1,
                icon: 'icon-mendianguanli',
              },
            },
            {
              path: 'merchants/puditprise',
              name: 'puditprise',
              component: 'merchants/StoreSet/AuditPrise.vue',
              meta: {
                title: '等待审核',
                isShow: 0,
              },
            },
            {
              path: 'merchants/changeenterprise',
              name: 'changeenterprise',
              component: 'merchants/StoreSet/ChangeEnterprise.vue',
              meta: {
                title: '修改企业信息',
                isShow: 0,
              },
            },

            {
              path: 'merchants/changemoney',
              name: 'changemoney',
              component: 'merchants/StoreSet/ChangeMoney.vue',
              meta: {
                title: '修改收款信息',
                isShow: 0,
              },
            },

            {
              path: 'merchants/orderz/orderd',
              name: 'orderd',
              component: 'merchants/Order/Orderz/Orderd.vue',
              meta: {
                title: '待支付',
                isShow: 0,
              },
            },
            {
        path: 'platform/orderz/orderz',
        name: 'orderDetails',
        component: 'platform/Order/Orderz/Orderz.vue',
        meta: {
          title: '待支付',
          isShow:0,
        },
      },
      {
        path: 'platform/orderz/orderdr',
        name: 'orderdr',
        component: 'platform/Order/Orderz/Orderdr.vue',
        meta: {
          title: '待确认',
          isShow:0,
        },
      },
      {
        path: 'platform/orderz/orderfw',
        name: 'orderfw',
        component: 'platform/Order/Orderz/Orderfw.vue',
        meta: {
          title: '待服务',
          isShow:0,
        },
      },
      {
        path: 'platform/orderz/orderwc',
        name: 'orderwc',
        component: 'platform/Order/Orderz/Orderwc.vue',
        meta: {
          title: '已完成',
          isShow:0,
        },
      },
      {
        path: 'platform/orderz/orderqx',
        name: 'orderqx',
        component: 'platform/Order/Orderz/Orderqx.vue',
        meta: {
          title: '已取消',
          isShow:0,
        },
      },
      {
        path: 'platform/orderz/ordert',
        name: 'ordert',
        component: 'platform/Order/Orderz/Ordert.vue',
        meta: {
          title: '退款中',
          isShow:0,
        },
      },
      {
        path: 'platform/orderz/ordertk',
        name: 'ordertk',
        component: 'platform/Order/Orderz/Ordertk.vue',
        meta: {
          title: '已退款',
          isShow:0,
        },
      },
          ],
        },
        {
          path: '/*',
          redirect: '/404',
        },
      ],
      routerRender2: [
        {
          path: '/home',
          name: 'home',
          component: 'Home.vue',
          redirect: '/home/welcome',
          children: [
            {
              path: 'welcome',
              name: 'welcome',
              component: 'platform/Welcome.vue',
              meta: {
                title: '主页',
                isShow: 1,
                icon: 'icon-shouye',
              },
            },
            {
              path: 'audit',
              name: 'audit',
              component: 'platform/Audit/Audit.vue',
              meta: {
                title: '入驻审核',
                isShow: 1,
                icon: 'icon-SQLshenhe',
              },
            },
            {
              path: 'auditDetail',
              name: 'auditDetail',
              component: 'platform/Audit/AuditDetail.vue',
              meta: {
                title: '入驻审核详情',
                isShow: 0,
              },
            },
            {
              path: 'user',
              name: 'user',
              redirect: '/home/user/beauty',
              meta: {
                title: '用户管理',
                isShow: 1,
                icon: 'icon-yonghuguanli',
              },
              component: 'platform/user/User.vue',
              children: [
                {
                  path: 'beauty',
                  name: 'beauty',
                  component: 'platform/user/BeautyTherapist.vue',
                  meta: {
                    title: '美疗师管理',
                    isShow: 1,
                    icon: 'icon-nvshangjia',
                  },
                },
                {
                  path: 'consumer',
                  name: 'consumer',
                  component: 'platform/user/Consumer.vue',
                  meta: {
                    title: '消费者管理',
                    isShow: 1,
                    icon: 'icon-xiaofeizheguanli',
                  },
                },
                {
                  path: '/ConsumerDetails',
                  name: 'ConsumerDetails',
                  component: 'platform/user/store/ConsumerDetails.vue',
                  meta: {
                    title: '消费者详情',
                    isShow: 0,
                  },
                },
                // {
                //   path: 'store',
                //   name: 'store',
                //   component: 'platform/user/store/Store.vue',
                //   meta: {
                //     title: '门店管理',
                //     isShow: 1,
                //     icon: 'icon-mendianguanli',
                //   },
                // },
              ],
            },
            {
              path: 'order',
              name: 'order',
              component: 'platform/Order/Order.vue',
              meta: {
                title: '订单管理',
                isShow: 1,
                icon: 'icon-dingdanguanli35',
              },
            },
            {
        path: 'merchants/orderz/orderd',
        name: 'orderDetails',
        component: 'merchants/Order/Orderz/Orderd.vue',
        meta: {
          title: '待支付',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/orderf',
        name: 'orderfuwu',
        component: 'merchants/Order/Orderz/Orderf.vue',
        meta: {
          title: '待服务',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/orderwc',
        name: 'orderwc',
        component: 'merchants/Order/Orderz/Orderwc.vue',
        meta: {
          title: '已完成',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/ordert',
        name: 'ordert',
        component: 'merchants/Order/Orderz/Ordert.vue',
        meta: {
          title: '退款中',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/ordertk',
        name: 'ordertk',
        component: 'merchants/Order/Orderz/Ordertk.vue',
        meta: {
          title: '已退款',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/orderq',
        name: 'orderq',
        component: 'merchants/Order/Orderz/Orderq.vue',
        meta: {
          title: '已取消',
          isShow: 0,
        },
      },
            {
              path: 'service',
              name: 'service',
              component: 'platform/Service/ServiceIndex.vue',
              meta: {
                title: '服务管理',
                isShow: 1,
                icon: 'icon-fuwuguanli',
              },
              children: [
                {
                  path: 'service',
                  name: 'service',
                  component: 'platform/Service/Service.vue',
                  meta: {
                    title: '服务管理',
                    isShow: 1,
                    icon: 'icon-fuwuguanli',
                  },
                },
                {
                  path: 'sensitive',
                  name: 'sensitive',
                  component: 'platform/Service/Sensitive.vue',
                  meta: {
                    title: '敏感词管理',
                    isShow: 1,
                    icon: 'icon-minganci',
                  },
                },
              ],
            },
            {
              path: 'financial',
              name: 'financial',
              component: 'platform/Financial/FinancialIndex.vue',
              meta: {
                title: '财务管理',
                isShow: 1,
                icon: 'icon-caiwuguanli',
              },
              children: [
                {
                  path: 'financial',
                  name: 'financial',
                  component: 'platform/Financial/Financial.vue',
                  meta: {
                    title: '财务管理',
                    isShow: 1,
                    icon: 'icon-caiwuguanli',
                  },
                },
                {
                  path: 'settlement',
                  name: 'settlement',
                  component: 'platform/Financial/Settlement.vue',
                  meta: {
                    title: '结算设置',
                    isShow: 1,
                    icon: 'icon-caiwuguanli',
                  },
                },
              ]
            },
            {
              path: 'permissions',
              name: 'permissions',
              meta: {
                title: '权限管理',
                isShow: 1,
                icon: 'icon-shenqingquanxian',
              },
              component: 'platform/Permissions/Permissions.vue',
            },
            {
              path: 'evaluation',
              name: 'evaluation',
              component: 'platform/Evaluation/Evaluation.vue',
              meta: {
                title: '评价管理',
                isShow: 1,
                icon: 'icon-weiyuejin',
              },
            },
          ],
        },
        {
          path: '/*',
          redirect: '/404',
        },
      ],
      routerRender3: [
        {
          path: '/home',
          name: 'home',
          component: 'Home.vue',
          redirect: '/home/welcome',
          children: [
            {
              path: 'welcome',
              name: 'welcome',
              component: 'platform/Welcome.vue',
              meta: {
                title: '主页',
                isShow: 1,
                icon: 'icon-shouye',
              },
            },
            {
              path: 'audit',
              name: 'audit',
              component: 'platform/Audit/Audit.vue',
              meta: {
                title: '入驻审核',
                isShow: 1,
                icon: 'icon-SQLshenhe',
              },
            },
            {
              path: 'auditDetail',
              name: 'auditDetail',
              component: 'platform/Audit/AuditDetail.vue',
              meta: {
                title: '入驻审核详情',
                isShow: 0,
              },
            },
            {
              path: 'user',
              name: 'user',
              redirect: '/home/user/beauty',
              meta: {
                title: '用户管理',
                isShow: 1,
                icon: 'icon-yonghuguanli',
              },
              component: 'platform/user/User.vue',
              children: [
                {
                  path: 'beauty',
                  name: 'beauty',
                  component: 'platform/user/BeautyTherapist.vue',
                  meta: {
                    title: '美疗师管理',
                    isShow: 1,
                    icon: 'icon-nvshangjia',
                  },
                },
                {
                  path: 'consumer',
                  name: 'consumer',
                  component: 'platform/user/Consumer.vue',
                  meta: {
                    title: '消费者管理',
                    isShow: 1,
                    icon: 'icon-xiaofeizheguanli',
                  },
                },
                {
                  path: '/ConsumerDetails',
                  name: 'ConsumerDetails',
                  component: 'platform/user/store/ConsumerDetails.vue',
                  meta: {
                    title: '消费者详情',
                    isShow: 0,
                  },
                },
                // {
                //   path: 'store',
                //   name: 'store',
                //   component: 'platform/user/store/Store.vue',
                //   meta: {
                //     title: '门店管理',
                //     isShow: 1,
                //     icon: 'icon-mendianguanli',
                //   },
                // },
              ],
            },
            {
              path: 'order',
              name: 'order',
              component: 'platform/Order/Order.vue',
              meta: {
                title: '订单管理',
                isShow: 1,
                icon: 'icon-dingdanguanli35',
              },
            },
            {
        path: 'merchants/orderz/orderd',
        name: 'orderDetails',
        component: 'merchants/Order/Orderz/Orderd.vue',
        meta: {
          title: '待支付',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/orderf',
        name: 'orderfuwu',
        component: 'merchants/Order/Orderz/Orderf.vue',
        meta: {
          title: '待服务',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/orderwc',
        name: 'orderwc',
        component: 'merchants/Order/Orderz/Orderwc.vue',
        meta: {
          title: '已完成',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/ordert',
        name: 'ordert',
        component: 'merchants/Order/Orderz/Ordert.vue',
        meta: {
          title: '退款中',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/ordertk',
        name: 'ordertk',
        component: 'merchants/Order/Orderz/Ordertk.vue',
        meta: {
          title: '已退款',
          isShow: 0,
        },
      },
      {
        path: 'merchants/orderz/orderq',
        name: 'orderq',
        component: 'merchants/Order/Orderz/Orderq.vue',
        meta: {
          title: '已取消',
          isShow: 0,
        },
      },
            {
              path: 'service',
              name: 'service',
              component: 'platform/Service/ServiceIndex.vue',
              meta: {
                title: '服务管理',
                isShow: 1,
                icon: 'icon-fuwuguanli',
              },
              children: [
                {
                  path: 'service',
                  name: 'service',
                  component: 'platform/Service/Service.vue',
                  meta: {
                    title: '服务管理',
                    isShow: 1,
                    icon: 'icon-fuwuguanli',
                  },
                },
                {
                  path: 'sensitive',
                  name: 'sensitive',
                  component: 'platform/Service/Sensitive.vue',
                  meta: {
                    title: '敏感词管理',
                    isShow: 1,
                    icon: 'icon-minganci',
                  },
                },
              ],
            },
            {
              path: 'financial',
              name: 'financial',
              component: 'platform/Financial/Financial.vue',
              meta: {
                title: '财务管理',
                isShow: 1,
                icon: 'icon-caiwuguanli',
              },
            },
            {
              path: 'evaluation',
              name: 'evaluation',
              component: 'platform/Evaluation/Evaluation.vue',
              meta: {
                title: '评价管理',
                isShow: 1,
                icon: 'icon-weiyuejin',
              },
            },
          ],
        },
        {
          path: '/*',
          redirect: '/404',
        },
      ]
    };
  },
  methods: {
    async login () {

      if (this.type === '1') {
        //商户
        const res = await this.$axios.get('http://172.16.113.187:8080/store/login', {
          params: {
            postbox: this.loginForm.username,
            pwd: this.loginForm.password
          }
        })
        console.log(res)
        if (res.code !== 200) return this.$message.error('登录失败,请检查用户名或密码！')
        let userInfo = {}
        userInfo.id = res.data.shopInFo.id
        userInfo.username = res.data.shopInFo.boss
        userInfo.address = res.data.shopInFo.bankLocation
        userInfo.number = res.data.shopInFo.postbox
        this.$store.commit('routers/routers', this.routerRender1)
        this.$store.commit('routers/setToken', res.data.token)
        this.$store.commit('routers/setUserInfo', userInfo)

      } else {
        //平台
        const res = await this.$axios.get('http://172.16.113.187:8080/platform/login', {
          params: {
            account: this.loginForm.username,
            pwd: this.loginForm.password
          }
        })
        // console.log(res)
        if (res.code !== 200) return this.$message.error('登录失败,请检查用户名或密码！')
        let userInfo = {}
        userInfo.id = res.data.adminInfo.id
        userInfo.username = res.data.adminInfo.name
        userInfo.state = res.data.adminInfo.state
        userInfo.account = res.data.adminInfo.account
        if (res.data.adminInfo.state === 1) {
          this.$store.commit('routers/routers', this.routerRender2)
        } else {
          this.$store.commit('routers/routers', this.routerRender3)
        }
        this.$store.commit('routers/setToken', res.data.token)
        this.$store.commit('routers/setUserInfo', userInfo)

      }
      this.$message.success(`登录成功，欢迎您:${this.$store.state.routers.userInfo.username}`)
      this.$router.push({ name: 'home' })
    },
    register () {
      this.$message.warning('不允许注册,请联系管理员新建账号!')
    }
  },
  computed: {},
  watch: {},
};
</script>

<style scoped lang="less">
.title {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  height: 80px;
  line-height: 80px;
  margin: 0;
}
.el-card {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 40%;
  height: 400px;
  overflow: visible;
  img {
    width: 100px;
    border-radius: 50%;
    position: absolute;
    top: -50px;
    left: calc(50% - 50px);
  }
  .el-form {
    margin-top: 20px;
    .el-form-item {
      width: 60%;
      margin-left: 80px;
    }
  }
}
#register {
  margin-left: 60px;
}
</style>
